﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VgoCardChange.Models.Objects;
using VgoCardChange.Models.DAL;

namespace VgoCardChange.Models
{
    public class TransactionLogModels
    {
        public List<TransactionLog> GetTransactionLog()
        {
            List<TransactionLog> listTrSL = new List<TransactionLog>();
            ConnectDB con = new ConnectDB();
            try
            {
                string sql = "select TransID,FullName,TransDate,IpAddress,UserAgent,TransStatus,CardSupplierID,CardNumber,SeriNumber,Money,Bonus,Description,GameName from TblTransactionLog join TblUser on TblTransactionLog.UserID=TblUser.UserID join TblGame on TblTransactionLog.GameID=TblGame.GameID  ";
                con.ExeReader(sql);
                while (con.dataRead.Read())
                {
                    TransactionLog TrSL = new TransactionLog();
                    TrSL.TransID = con.dataRead["TransID"].ToString();
                    TrSL.UserID = int.Parse(con.dataRead["UserID"].ToString());
                    TrSL.TransDate = DateTime.Parse(con.dataRead["TransDate"].ToString());
                    TrSL.IpAddress = con.dataRead["IpAddress"].ToString();
                    TrSL.UserAgent = con.dataRead["UserAgent"].ToString();
                    TrSL.TransStatus = con.dataRead["TransStatus"].ToString();
                    TrSL.CardSupplierID = con.dataRead["CardSupplierID"].ToString();
                    TrSL.CardNumber = con.dataRead["CardNumber"].ToString();
                    TrSL.SeriNumber = con.dataRead["SeriNumber"].ToString();
                    TrSL.Money =double.Parse(con.dataRead["Money"].ToString());
                    TrSL.Bonus=double.Parse(con.dataRead["Bonus"].ToString());
                    TrSL.Description=con.dataRead["Description"].ToString();
                    TrSL.GameName = con.dataRead["GameName"].ToString();
                    listTrSL.Add(TrSL);


                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);

            }
            finally { con.CloseData(); con = null; }
            return listTrSL;

        }
        public List<TransactionLog> SearchTranID(string TranID)
        {
            List<TransactionLog> listsearchTrSL = new List<TransactionLog>();
            ConnectDB con = new ConnectDB();
            try
            {
                string sql = "select TransID,UserID,TransDate,IpAddress,UserAgent,TransStatus,CardSupplierID,CardNumber,SeriNumber,Money,Bonus,Description from TblTransactionLog where TransID like N'%" + TranID + "%' ";
                con.ExeReader(sql);
                while (con.dataRead.Read())
                {
                    TransactionLog TrSL = new TransactionLog();
                    TrSL.TransID = con.dataRead["TransID"].ToString();
                    TrSL.UserID = int.Parse(con.dataRead["UserID"].ToString());
                    TrSL.TransDate = DateTime.Parse(con.dataRead["TransDate"].ToString());
                    TrSL.IpAddress = con.dataRead["IpAddress"].ToString();
                    TrSL.UserAgent = con.dataRead["UserAgent"].ToString();
                    TrSL.TransStatus = con.dataRead["TransStatus"].ToString();
                    TrSL.CardSupplierID = con.dataRead["CardSupplierID"].ToString();
                    TrSL.CardNumber = con.dataRead["CardNumber"].ToString();
                    TrSL.SeriNumber = con.dataRead["SeriNumber"].ToString();
                    TrSL.Money = double.Parse(con.dataRead["Money"].ToString());
                    TrSL.Bonus = double.Parse(con.dataRead["Bonus"].ToString());
                    TrSL.Description = con.dataRead["Description"].ToString();
                    listsearchTrSL.Add(TrSL);


                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);

            }
            finally { con.CloseData(); con = null; }
            return listsearchTrSL;

 
        }
        public List<TransactionLog> SearchUserName(string UserName)
        {
            List<TransactionLog> listsearchusername = new List<TransactionLog>();
            ConnectDB con = new ConnectDB();
            try
            {
                string sql = "select TransID,TblUser.UserID,TransDate,IpAddress,UserAgent,TransStatus,CardSupplierID,CardNumber,SeriNumber,Money,Bonus,Description from TblTransactionLog join TblUser on TblTransactionLog.UserID=TblUser.UserID where UserName like N'%" + UserName + "%' ";
                con.ExeReader(sql);
                while (con.dataRead.Read())
                {
                    TransactionLog TrSL = new TransactionLog();
                    TrSL.TransID = con.dataRead["TransID"].ToString();
                    TrSL.UserID =int.Parse(con.dataRead["UserID"].ToString());
                    TrSL.TransDate = DateTime.Parse(con.dataRead["TransDate"].ToString());
                    TrSL.IpAddress = con.dataRead["IpAddress"].ToString();
                    TrSL.UserAgent = con.dataRead["UserAgent"].ToString();
                    TrSL.TransStatus = con.dataRead["TransStatus"].ToString();
                    TrSL.CardSupplierID = con.dataRead["CardSupplierID"].ToString();
                    TrSL.CardNumber = con.dataRead["CardNumber"].ToString();
                    TrSL.SeriNumber = con.dataRead["SeriNumber"].ToString();
                    TrSL.Money = double.Parse(con.dataRead["Money"].ToString());
                    TrSL.Bonus = double.Parse(con.dataRead["Bonus"].ToString());
                    TrSL.Description = con.dataRead["Description"].ToString();
                    listsearchusername.Add(TrSL);


                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);

            }
            finally { con.CloseData(); con = null; }
            return listsearchusername;

 
        }
    }
}